import 'package:flutter/material.dart';
import 'package:flutter_custom_view/flutter_custom_view.dart';
class CheckSmearPage extends StatefulWidget {
  const CheckSmearPage({Key? key}) : super(key: key);

  @override
  State<CheckSmearPage> createState() => _CheckSmearPageState();
}

class _CheckSmearPageState extends State<CheckSmearPage> {
  List<Color> colorList = List.generate(400, (index) => Colors.black);
  Color startColor = Colors.red;
  int brightness=100;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Container(
        color:  const Color.fromRGBO(16, 15, 18,1.0),
        // padding: const EdgeInsets.symmetric(horizontal: 16,vertical: 10),
        child: Column(
          children: [
            Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(2),
                  border: Border.all(
                    width: 2,
                    color: Colors.grey,
                  ),
                ),
                child: CheckSmearWidget(
                  colorList: colorList,
                  number: 400,
                  type: SwearType.block,
                  startColor: HSVColor.fromColor(startColor).withValue(brightness / 100).toColor(),
                  bgColor: Colors.grey,
                  onClickColorList: (list) {
                    // print("onClickColorList:${list.length}");
                    setState(() {
                      colorList = list;
                    });
                  },
                  onClickColorListEnd: (list) {
                    // print("onClickColorListEnd:${list.length}");
                    setState(() {
                      colorList = list;
                    });
                  },
                )),
            const SizedBox(height: 10,),
            InkWell(
              onTap: (){
                setState(() {
                  colorList = List.generate(400, (index) => Colors.black);
                });
              },
              child: Container(
                width: 100,
                height: 50,
                color: Colors.white,
                child: Text("清空数据"),
              ),
            ),
            SizedBox(
              height: 150,
              child: RectangleColorPicker(
                selectRadius: 16,
                initialColor: startColor,
                aspectRatio: 4 / 7,
                onCallBack: (
                    double h,
                    double s,
                    ) {
                  setState(() {
                    startColor = HSVColor.fromAHSV(1.0, h, s, 1.0).toColor();
                  });
                },
                onCallBackEnd: (
                    double h,
                    double s,
                    ) {
                  setState(() {
                    startColor = HSVColor.fromAHSV(1.0, h, s, 1.0).toColor();
                  });
                },
              ),
            ),
            AnimationSlider(
              isSingle: true,
              height: 50,
              min: 1,
              max: 100,
              icon: const Icon(Icons.color_lens_outlined),
              value: brightness.toDouble(),
              onValueChange: (_value) {
                setState(() {
                  brightness =_value.toInt();
                });
              },
            ),

          ],
        ),
      ),
    );
  }
}
